package com.ruix.app.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ruix.app.R;
import com.ruix.app.model.Comment;
import com.ruix.app.model.PostsCard;
import com.ruix.app.util.CopyUtil;
import com.ruix.app.util.ToastUtil;

/**
 * Created by hadexs on 2017/4/30.
 */

public class CopyCommentDialog extends Dialog implements View.OnClickListener{


    private String comment;
    private TextView deleteAction;

    public CopyCommentDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_copy_comment);
        setCanceledOnTouchOutside(true);
        //初始化界面控件
        //初始化界面控件的事件
        initEvent();

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;//宽高可设置具体大小
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);

    }

    private void initEvent(){
        findViewById(R.id.tv_copy_comment).setOnClickListener(this);
        findViewById(R.id.tv_cancel_action).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_copy_comment:
                dismiss();
                CopyUtil.clipboardCopy(getContext(),comment);
                ToastUtil.showNewSuccessMsg("已复制");
                break;

            case R.id.tv_cancel_action:
                dismiss();
                break;
        }
    }


    public void show(String content){
        if (!TextUtils.isEmpty(content)) {
            show();
        }
        this.comment = content;
    }
}
